package com.dragons.dragonsvf.controller.verification_code;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author dragons
 * @version 1.0.0
 * @description: 生成图形验证码并且存储验证
 * @date 2025/4/29 15:45
 */
@Service
public class CaptchaService {

    @Autowired
//    private RedisTemplate<String, String> redisTemplate;

    // 验证码有效期（秒）
    private static final long CAPTCHA_EXPIRATION = 300;

    // 存储验证码
    public void storeCaptcha(String sessionId, String captchaCode) {
//        redisTemplate.opsForValue().set(
//                "CAPTCHA:" + sessionId,
//                captchaCode,
//                CAPTCHA_EXPIRATION,
//                TimeUnit.SECONDS);
    }

    // 验证验证码
    public boolean validateCaptcha(String sessionId, String userInputCaptcha) {
//        String key = "CAPTCHA:" + sessionId;
//        String storedCaptcha = redisTemplate.opsForValue().get(key);
//
//        if (storedCaptcha != null && storedCaptcha.equalsIgnoreCase(userInputCaptcha)) {
//            // 验证成功后立即删除，防止重复使用
//            redisTemplate.delete(key);
//            return true;
//        }

        return false;
    }

}
